package com.zhengxin.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhengxin.entity.User;
import com.zhengxin.mapper.UserMapper;
import com.zhengxin.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserMapper userMapper;

    @Override
    public String login(JSONObject jsonObject) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        String name = jsonObject.getString("name");
        String password = jsonObject.getString("password");
        queryWrapper.eq(User::getName, name).eq(User::getPassword,password);
        User user = userMapper.selectOne(queryWrapper);
        if (user == null) {
            return "0";
        } else {
            return "1";
        }
    }
}
